/**
 * Created by Administrator on 2016/12/7.
 */
//市场监管首页
var _module = require("../../models/scjg/scjg");
exports.index = function (req,res) {
    res.render('scjg/index', {
        title: '市场监管',
        current: 'scjg',
        dataSet: {}
    })
    // _module
    //     .getExceptionDir({
    //         pageRowNum:4
    //     })
    //     .getExceptionList({
    //     })
    //     .getCustCheck({
    //         pageRowNum:4
    //     })
    //     .getCheck({
    //         pageRowNum:4
    //     })
    //     .getPunish({
    //         pageRowNum:4
    //     })
    //     .getPunishCountList({
    //     //    处罚统计
    //     })
    //     .getRightCheck({
    //         // pageRowNum:4
    //     }).
    //     getCustCheckRight({
    //         orderDesc:"asc"
    // })
    // .done(function (data1,data2,data3,data4,data5,data6,data7,data8) {
    //     data1 = JSON.parse(data1);
    //     data2 = JSON.parse(data2);
    //     data3 = JSON.parse(data3);
    //     data4 = JSON.parse(data4);
    //     data5 = JSON.parse(data5);
    //     data6 = JSON.parse(data6);
    //     data7 = JSON.parse(data7);
    //     data8 = JSON.parse(data8);
    //     console.log(data8.data.dataList);
    //     res.render('scjg/index', {
    //         title: '市场监管',
    //         current: 'scjg',
    //         dataSet: {
    //             Check           : data3.data.dataList,  //抽查检查公示
    //             exceptionCount  : data2.data.dataList,  //异常经营统计
    //             exceptionList   : data1.data.dataList,  //异常经营
    //             examination     : data4.data.dataList,  //检验检测
    //             punish          : data5.data.dataList,  //行政处罚列表
    //             punishCount     : data6.data.dataList,  //行政处罚统计
    //             rightCheck      : data7.data.dataList,  //检验检测统计
    //             CheckRight      : data8.data.dataList   //抽查检查右侧
    //         }
    //     });

    // });



};

function dateToGs(type) {
    var d       = new Date();
    // 当前日期
    var month   = d.getMonth() + 1 > 9 ? (d.getMonth() + 1 ) : '0' + (d.getMonth() + 1);
    var day     = d.getDate() > 9 ? d.getDate() : '0' + d.getDate();
    var endDate = d.getFullYear() + '-' + month + '-' + day;

    // 三十天前日期
    var bDi       = d.setDate(d.getDate() - 30);
    var bD        = new Date(bDi);
    var bMonth    = bD.getMonth() + 1 > 9 ? (bD.getMonth() + 1 ) : '0' + (bD.getMonth() + 1);
    var bDay      = bD.getDate() > 9 ? bD.getDate() : '0' + bD.getDate();
    var beginDate = bD.getFullYear() + '-' + bMonth + '-' + bDay;

    if (type == 'month') {
        var time = {
            beginDate: beginDate,
            endDate  : endDate
        }
    }

    if (type == 'year') {
        var time = {
            beginDate: d.getFullYear() + '-01-01',
            endDate  : endDate
        }
    }

    if (type == '') {
        var time = {
            beginDate: '',
            endDate  : ''
        }
    }

    return time;
}



//异常经营
exports.exceptionDir = function (req, res, next) {
    _module.getExceptionDir({
        regNum:req.body.regNum || '',
        beginDate:req.body.beginDate || '',
        endDate:req.body.endDate || '',
        pageRowNum:req.body.pageRowNum || '',
        pageIndex:req.body.pageIndex || ''
        })
        .done(function (data) {
            console.log(data);
            res.send(JSON.parse(data));

        });
    };
//异常经营统计
exports.exceptionList = function (req, res) {
    _module.getExceptionList({
        regNum:req.body.regNum || '',
        beginDate:req.body.beginDate || '',
        endDate:req.body.endDate || '',
        pageRowNum:req.body.pageRowNum || '',
        pageIndex:req.body.pageIndex || ''
    }).done(function(data){
        res.send(JSON.parse(data));
    })
};
//异常经营统计
exports.custCheck = function (req, res) {
    _module.getCustCheck({
        regNum:req.body.regNum || '',
        beginDate:req.body.beginDate || '',
        endDate:req.body.endDate || '',
        pageRowNum:req.body.pageRowNum || '',
        pageIndex:req.body.pageIndex || ''
    }).done(function(data){
        res.send(JSON.parse(data));
    })
};
//异常经营统计
exports.custCheckRight = function (req, res) {
    _module.getCustCheckRight({
        regNum:req.body.regNum || '',
        beginDate:req.body.beginDate || '',
        endDate:req.body.endDate || '',
        pageRowNum:req.body.pageRowNum || '',
        pageIndex:req.body.pageIndex || ''
    }).done(function(data){
        res.send(JSON.parse(data));
    })
};
//异常经营统计
exports.checkDeList = function (req, res) {
    _module.getCheck({
        regNum:req.body.regNum || '',
        beginDate:req.body.beginDate || '',
        endDate:req.body.endDate || '',
        pageRowNum:req.body.pageRowNum || '',
        pageIndex:req.body.pageIndex || ''
    }).done(function(data){
        res.send(JSON.parse(data));
    })
};
//检验检测右侧
exports.checkRightDeList = function (req, res) {
    _module.getRightCheck({
        regNum:req.body.regNum || '',
        beginDate:req.body.beginDate || '',
        endDate:req.body.endDate || '',
        pageRowNum:req.body.pageRowNum || '',
        pageIndex:req.body.pageIndex || ''
    }).done(function(data){
        res.send(JSON.parse(data));
    })
};
//异常经营统计
exports.Punish = function (req, res) {
    _module.getPunish({
        regNum:req.body.regNum || '',
        beginDate:req.body.beginDate || '',
        endDate:req.body.endDate || '',
        pageRowNum:req.body.pageRowNum || '',
        pageIndex:req.body.pageIndex || '',
        custName :req.body.custName || ''
    }).done(function(data){
        res.send(JSON.parse(data));
    })
};
//异常经营统计
exports.PunishCountList = function (req, res) {
    _module.getPunishCountList({
        regNum:req.body.regNum || '',
        beginDate:req.body.beginDate || '',
        endDate:req.body.endDate || '',
        pageRowNum:req.body.pageRowNum || '',
        pageIndex:req.body.pageIndex || ''
    }).done(function(data){
        res.send(JSON.parse(data));
    })
};
exports.illegal = function (req, res) {

    var type = req.body.type;
    if (type == 'oths') {
        var publishDateBegin = req.body.publishDateBegin || '',
            publishDateEnd   = req.body.publishDateEnd || '';
    } else {
        var publishDateBegin = dateToGs(type).beginDate || '',
            publishDateEnd   = dateToGs(type).endDate || '';
    }
    _module.getIllegal({
        regNum:req.body.regNum || '',
        beginDate:publishDateBegin || '',
        endDate:publishDateEnd || '',
        pageRowNum:req.body.pageRowNum || '',
        pageIndex:req.body.pageIndex || '',
        custNameLike:req.body.custNameLike || '',
        custName :req.body.custName || ''
    }).done(function(data){
        console.log(req.body.custName,"12");
        res.send(JSON.parse(data));
    })
};
exports.illegalCount = function (req, res) {
    _module.getIllegalCount({
        regNum:req.body.regNum || '',
        beginDate:req.body.beginDate || '',
        endDate:req.body.endDate || '',
        pageRowNum:req.body.pageRowNum || '',
        pageIndex:req.body.pageIndex || ''
    }).done(function(data){
        res.send(JSON.parse(data));
    })
};








//抽查检查列表
exports.ccjc = function (req, res) {
    res.render('scjg/ccjc',{
        title:"抽查检查列表",
        current:"scjg",
        dataSet:{

        }
    })
};

//严重违法详情
exports.yzwf = function (req, res) {
    res.render('scjg/yzwf',{
        title:"抽查检查列表",
        current:"scjg",
        dataSet:{

        }
    })
};

//异常经营列表
exports.jyyc = function (req, res) {
    res.render('scjg/jyyc',{
        title:"异常经营列表",
        current:"scjg",
        dataSet:{

        }
    })
};

//检测检验列表
exports.jcjy = function (req, res) {
    res.render('scjg/jcjy',{
        title:"抽查检查列表",
        current:"scjg",
        dataSet:{

        }
    })
};

//行政处罚列表
exports.xzcf = function (req, res) {
    res.render('scjg/xzcf',{
        title:"行政处罚列表",
        current:"scjg",
        dataSet:{

        }
    })
};



//商事主体信息
exports.institutional = function (req, res) {
    res.render('institutional',{
        title:"商事主体信息",
        current:"scjg",
        dataSet:{

        }
    })
};